// 重载
type UnionType = string | number;
// 函数定义
function sum(x: number, y: number): number;
function sum(x: string, y: string): string;
function sum(x: string, y: number): string;
function sum(x: number, y: string): string;

// 函数实现
function sum(x: UnionType, y: UnionType) {
  if (typeof x === 'string' || typeof y === 'string') {
    return x.toString() + y.toString();
  }
  return x + y;
}

const res = sum(1, 2)
const res1 = sum('1', '2')
const res2 = sum('你', '好')

console.log(res)
console.log(res1)

console.log(res2.split(''))